【发布时间】:2017-07-31 04:58:07
【问题描述】:
目前正在抓取一个使用 javascript 的房地产网站。我的过程首先为单个列表抓取包含许多不同 href 链接的列表,将这些链接附加到另一个列表,然后按下一步按钮。我这样做直到下一个按钮不再可点击。
我的问题是,在收集所有列表(约 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
在此之后,我有另一个简单的抓取工具,它遍历列表,在 selenium 中打开它们并收集该列表的数据。
for links in houselinklist:
print(links)
newwebpage = links
driver.get(newwebpage)
html = driver.page_source
soup = bs.BeautifulSoup(html,'html.parser')
.
.
.
. more code here
【问题讨论】:
-
你要抓取的链接在哪里?
-
你遇到了什么错误?
标签: python selenium web-scraping beautifulsoup