Python BeautifulSoup 返回空列表

2023-12-13

我正在尝试创建一个 Python 脚本来使用 BeautifulSoup 从 tcgplayer.com 获取 Yugioh 卡的价格。当您在此网站上搜索卡片时,它会返回一页搜索结果,其中包含来自不同卖家的多个价格。我的目标是拉低所有这些价格。在下面的示例中,我打开名为“A”细胞育种设备的卡片的搜索​​结果:

import urllib2
from bs4 import BeautifulSoup
html = urllib2.open('http://shop.tcgplayer.com/productcatalog/product/show?newSearch=false&ProductType=All&IsProductNameExact=false&ProductName=%22A%22%20Cell%20Breeding%20Device')
soup = BeautifulSoup(html, 'lxml')
soup.find_all('span', {'class': 'scActualPrice largetext pricegreen'})

几天前,正确运行 soup.find_all 行给了我所需的信息。然而,现在运行它会给我一个空数组[]。我已经广泛搜索了 BeautifulSoup 返回空数组的信息,但我不确定其中是否有任何一个适用于我,因为它几天前工作得很好。有人可以帮我指出正确的方向吗?先感谢您!


你应该使用selenium使用真实浏览器进行报废:

from selenium import webdriver

driver = webdriver.Chrome('/path/to/chromedriver')
driver.get('http://shop.tcgplayer.com/productcatalog/product/show?newSearch=false&ProductType=All&IsProductNameExact=false&ProductName=%22A%22%20Cell%20Breeding%20Device')
prices = driver.find_elements_by_css_selector('.scActualPrice')
for element in prices:
    print(element.text)
driver.quit()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python BeautifulSoup 返回空列表 的相关文章

随机推荐