【发布时间】:2021-01-17 21:39:36
【问题描述】:
上下文
我目前正在学习关于网络抓取的课程。在抓取 javascript 模块时,使用函数 set_1.difference(set_2) 将旧变量与新创建的变量区分开来。但是当我这样做时,它带来了这个错误:
AttributeError: 'list' object has no attribute 'difference'
我在网上搜索并偶然发现了这个website。但是在他们自己的网站上运行这个例子却报错了
问题
这不起作用的任何原因?我想打印新生成的 javascript 链接。以下是我尝试运行的代码:
from requests_html import AsyncHTMLSession
session = AsyncHTMLSession()
r = await session.get('https://www.ons.gov.uk/economy/economicoutputandproductivity/output/datasets/economicactivityfasterindicatorsuk')
r.status_code
divs = r.html.find('div')
downloads = r.html.find('a')
urls = r.html.absolute_links
# Now need to render the javascript. Downloads chromium the first time we use it,
# It is a browser that has no GUI
await r.html.arender()
new_divs = r.html.find('div')
new_downloads = r.html.find('a')
new_urls = r.html.absolute_links
# Get only the newly created html
new_downloads.difference(downloads)
【问题讨论】:
标签: javascript python web-scraping python-requests