我一直试图取消用户评论从DM网站没有任何运气。 示例页:https://www.dm.de/l-oreal-men-expert-men-expert-vita-lift-vitalisierende-feuchtigkeitspflege-p3600523606276.html
我试着用beautifulsoup4和scrapy加载产品详细信息页面。你知道吗
from bs4 import BeautifulSoup
import requests
url = "https://www.dm.de/l-oreal-men-expert-men-expert-vita-lift-vitalisierende-feuchtigkeitspflege-p3600523606276.html"
response = requests.get(url)
print(response.text)
运行代码不会显示评论的内容-就像你从亚马逊.de! 它只显示网站上的脚本。你知道吗
编辑: 从Dev工具中可以看到,reviwes存储在JSON中的以下文件夹中。这正是我想提取的。你知道吗
我已经尝试了很多,以正确地刮与刮和bs4的DM产品详细资料页,但没有得到一个100%准确的刮刀。这就是为什么我决定搬到硒。这是缓慢的,但给100%准确的刮削结果。你知道吗
我没有时间玩params,但是请求url中的所有内容都是为了获取json。你知道吗
输出:
。。。。你知道吗
编辑:
为了使这个更紧凑,需要做大量的清理工作,但这里有一个基本问题:
就像大多数现代网站一样德国马克仅在页面最初加载后通过javascript加载内容。这是有问题的,因为pythons请求library和scrapy只处理http,而不加载任何javascript。你知道吗
同样的事情也发生在amazon上,但是在那里它被检测到了,并且你得到了一个无javascript的版本。你知道吗
您可以在浏览器中禁用javascript,然后打开要刮取的站点,自己尝试一下。你知道吗
解决方案包括使用支持javascript的scraper,或者使用自动浏览器scrape(使用完整的浏览器当然也支持js)。硒和铬对我很有效。你知道吗
相关问题 更多 >
编程相关推荐