Javascript Scrapy Selenium爬网JS加载的网页
现在我要练习抓取一个加载了javascript的网站。 我使用chrome来检查元素,我可以找到相应的代码,但当我查看页面源代码时,我什么也找不到 具体地说,我正在爬行,我希望在这个网页中获得小程序URL 我现在所做的是像下面这样使用scrapy和seleniumJavascript Scrapy Selenium爬网JS加载的网页,javascript,selenium,dynamic,scrapy,web-crawler,Javascript,Selenium,Dynamic,Scrapy,Web Crawler,现在我要练习抓取一个加载了javascript的网站。 我使用chrome来检查元素,我可以找到相应的代码,但当我查看页面源代码时,我什么也找不到 具体地说,我正在爬行,我希望在这个网页中获得小程序URL 我现在所做的是像下面这样使用scrapy和selenium def parse(self, response): print("procesing:"+response.url) # print(response.body) # blog_urls=
def parse(self, response):
print("procesing:"+response.url)
# print(response.body)
# blog_urls=response.xpath("//li[@class='my-web-applet-card web-applet-card'][4]").extract()
# print(blog_urls)
self.browser.get(response.url)
tt=self.browser.find_element_by_xpath("//li[@class='my-web-applet-card web-applet-card'][4]")
print(tt)
def process_response(self, request, response, spider):
# Called with the response returned from the downloader.
# Must either;
# - return a Response object
# - return a Request object
# - or raise IgnoreRequest
spider.browser.get(url=request.url)
time.sleep(10)
# row_response = spider.browser.page_source
row_response = spider.browser.execute_script("return document.getElementsByTagName('html')")
print(row_response)
return HtmlResponse(url=spider.browser.current_url, body=row_response, encoding="utf8", request=request)
此页面的数据来自“”,因此最好直接访问该页面,这太酷了!谢谢你的提示。