Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python美化组返回空列表_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python美化组返回空列表

Python美化组返回空列表,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我正在尝试创建一个Python脚本,使用BeautifulSoup从tcgplayer.com获取Yugioh卡的价格。当你在这个网站上搜索一张卡片时,它会返回一页搜索结果,其中包含来自不同卖家的几个价格。我的目标是拉动所有这些价格。在下面的示例中,我打开了一张名为“a”细胞繁殖设备的卡片的搜索结果: import urllib2 from bs4 import BeautifulSoup html = urllib2.open('http://shop.tcgplayer.com/produc

我正在尝试创建一个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返回一个空数组,我已经搜索了相当广泛的内容,但我不确定是否有任何内容适用于我,因为它在几天前工作得还不错。有人能帮我指出正确的方向吗?提前谢谢你

此网站使用一种名为Incapsula的服务。网站开发者将Incapsula配置为阻止机器人访问其内容

我建议您联系他们的管理员,请求访问或要求他们提供API。

您应该使用real browser:

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()

使用selenium对我来说很有效,但你认为它会在几天内停止工作吗?使用selenium,你实际上是在打开浏览器并完成所有操作,所以现在应该还可以。但将来可能会有机会。而且使用selenium是不可靠的