Tag: scraping lxml

无法在Excel文件中正确写入提取的项目?

我已经写了一些代码在pythonparsing标题和链接从一个网页。 最初,我试图parsing左侧栏中的链接,然后通过追踪每个链接来抓取每个页面上的上述文档。 我完美无瑕地做到了这一点。 我试图将不同页面的文档保存在一个excel文件中。 但是,它创build了几个“表格”,从我的脚本的标题variables中提取所需的部分作为表格名称。 我面临的问题是,当数据被保存时,只有链接中每个页面的最后一个logging保存在我的Excel表格中,而不是完整的logging。 这是我尝试的脚本: import requests from lxml import html from pyexcel_ods3 import save_data web_link = "http://www.wiseowl.co.uk/videos/" main_url = "http://www.wiseowl.co.uk" def get_links(page): response = requests.Session().get(page) tree = html.fromstring(response.text) data = {} titles = tree.xpath("//ul[@class='woMenuList']//li[@class='woMenuItem']/a/@href") for title in titles: if "author" not in title and "year" not in title: get_docs(data, main_url + title) […]