【发布时间】:2021-03-15 03:05:00
【问题描述】:
我在尝试捕获页面内的特定信息时遇到问题。
网址:https://www.target.com/p/prairie-farms-vitamin-d-milk-1gal/-/A-47103206#lnk=sametab
在此页面上,我想要抓取的“关于此商品”下的“详细信息”选项卡旁边有名为“标签信息”、“运输和退货”、“问答”的隐藏选项卡.
我发现在使用 Beautifulsoup 进行 scraping 之前,我需要点击这些元素。
这是我的代码,假设我有每个链接的 pid。
url = 'https://www.target.com' + str(pid)
driver.get(url)
driver.implicitly_wait(5)
soup = bs(driver.page_source, "html.parser")
wait = WebDriverWait(driver, 3)
button = soup.find_all('li', attrs={'class': "TabHeader__StyledLI-sc-25s16a-0 jMvtGI"})
index = button.index('tab-ShippingReturns')
print('The index of ShippingReturns is:', index)
if search(button, 'tab-ShippingReturns'):
button_shipping_returns = button[index].find_element_by_id("tab-ShippingReturns")
button_shipping_returns.click()
time.sleep(3)
我的代码返回 ResultSet 对象没有属性“find_element_by_id”。您可能将元素列表视为单个元素。当你打算调用 find() 时,你调用了 find_all() 吗?
谁能指导我如何解决这个问题?
【问题讨论】:
-
这是 scrape 而不是 scrap。
标签: python beautifulsoup web-crawler