当前正在使用javascript进行搜索的房地产网站。我的过程首先为包含单个列表的包含多个不同href链接的列表开始,将这些链接附加到另一个列表,然后按下一个按钮。我这样做直到下一个按钮不再可点击。使用selenium,beautifulsoup和python进行网页扫描
我的问题是,收集所有列表(~13000链接)后,刮板不会移动到第二部分,打开链接并获取我需要的信息。 Selenium甚至不打开链接列表的第一个元素。
继承人我的代码:
wait = WebDriverWait(driver, 10)
while True:
try:
element = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, 'next')))
html = driver.page_source
soup = bs.BeautifulSoup(html,'html.parser')
table = soup.find(id = 'search_main_div')
classtitle = table.find_all('p', class_= 'title')
for aaa in classtitle:
hrefsyo = aaa.find('a', href = True)
linkstoclick = hrefsyo.get('href')
houselinklist.append(linkstoclick)
element.click()
except:
pass
在此之后我还有一个简单的刮刀,通过列表的例子不胜枚举,打开它们的硒和收集对目录资料。
for links in houselinklist:
print(links)
newwebpage = links
driver.get(newwebpage)
html = driver.page_source
soup = bs.BeautifulSoup(html,'html.parser')
.
.
.
. more code here
您正在刮的链接在哪里? – ksai
https://www.28hse.com/cn/rent/house-type-g1 – bathtubandatoaster
你得到了什么错误? – ksai