url传递html字符串,将Selenium HTML字符串传递给Scrapy以将url添加到Scrapy的url列表中...
我對Python,Scrapy和Selenium還很陌生。因此,如果您能提供任何幫助,我們將不勝感激。在
我希望能夠將從Selenium獲得的HTML作為頁面源,并將其處理為一個糟糕的響應對象。主要原因是能夠將Selenium Webdriver頁面源代碼中的url添加到Scrapy將解析的url列表中。在
再次感謝任何幫助。在
作為一個快速的第二個問題,有沒有人知道如何查看在或曾經在名單的網址,找到和刮取?在
謝謝!在
*******編輯********
這里有一個我正在嘗試做的例子。我搞不懂第五部分。在class AB_Spider(CrawlSpider):
name = "ab_spider"
allowed_domains = ["abcdef.com"]
#start_urls = ["https://www.kickstarter.com/projects/597507018/pebble-e-paper-watch-for-iphone-and-android"
#, "https://www.kickstarter.com/projects/801465716/03-leagues-under-the-sea-the-seaquestor-flyer-subm"]
start_urls = ["https://www.abcdef.com/page/12345"]
def parse_abcs(self, response):
sel = Selector(response)
URL = response.url
#part 1: check if a certain element is on the webpage
last_chk = sel.xpath('//ul/li[@last_page="true"]')
a_len = len(last_chk)
#Part 2: if not, then get page via selenium webdriver
if a_len == 0:
#OPEN WEBDRIVER AND GET PAGE
driver = webdriver.Firefox()
driver.get(response.url)
#Part 3: run script to ineract with page until certain element appears
while a_len == 0:
print "ELEMENT NOT FOUND, USING SELENIUM TO GET THE WHOLE PAGE"
#scroll down one time
driver.execute_script("window.scrollTo(0, 1000000000);")
#get page source and check if last page is there
selen_html = driver.page_source
hxs = Selector(text=selen_html)
last_chk = hxs.xpath('//ul/li[@last_page="true"]')
a_len = len(last_chk)
driver.close()
#Part 4: extract the URLs in the selenium webdriver URL
all_URLS = hxs.xpath('a/@href').extract()
#Part 5: all_URLS add to the Scrapy URLs to be scraped
總結
以上是生活随笔為你收集整理的url传递html字符串,将Selenium HTML字符串传递给Scrapy以将url添加到Scrapy的url列表中...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html5调盒子边框大小,CSS3 -
- 下一篇: 2017年html5行业报告,云适配发布