[英]Scraping second page in Python gives Data of first Page
在Python中刮取第二頁會得到第一頁的數據。 這是有關代碼的一部分:
browser.get("https://XXXXXXXXX/0_9b34?P=2")
innerHTML = browser.execute_script("return document.body.innerHTML") #type = str #returns the inner HTML as a string
Eroom_M7_htmlpage = innerHTML
soup = BeautifulSoup(Eroom_M7_htmlpage, 'html.parser') #type = bs4.BeautifulSoup
htmlprettified = soup.prettify() #type = str
project_items = soup.find_all('td', attrs={'headers' : 'ID Item'})
如果答案是初學者友好的,我將不勝感激,因為我只有3個月的Python自學時間。 請在這件事上我真的需要幫助來完成我的項目:( ps:我看過兩篇關於此的文章,但沒有幫助/理解。
innerHTML = browser.execute_script("return document.body.innerHTML") #type = str #returns the inner HTML as a string
Eroom_M7_htmlpage = innerHTML
您應該返回page_source而不是javascript響應
.page_source
是您要使用的方法。
因此,執行所需的任何JavaScript,然后捕獲HTML
Eroom_M7_htmlpage = browser.page_source
而不是innerhtml
文檔---> 這里
硒使用的基本示例。
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://python.org')
html = driver.page_source
print(html)
它將輸出網頁源,該源存儲在變量html中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.