Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x Webscraping-列表返回空_Python 3.x_List_Web Scraping_Treeview - Fatal编程技术网

Python 3.x Webscraping-列表返回空

Python 3.x Webscraping-列表返回空,python-3.x,list,web-scraping,treeview,Python 3.x,List,Web Scraping,Treeview,我目前试图废弃页面,但我的列表返回为空。我不知道我的树图是错的还是我的循环。。。以及如何修改它 我的代码: url = "https://www.renault-retail-group.fr/concessions-renault.html" chrome_path = r"C:\Users\xxx\Desktop\chromedriver_win32 (1)\chromedriver.exe" driver = webdriver.Chrome(chrome_path) driver.ma

我目前试图废弃页面,但我的列表返回为空。我不知道我的树图是错的还是我的循环。。。以及如何修改它

我的代码:

url = "https://www.renault-retail-group.fr/concessions-renault.html"

chrome_path = r"C:\Users\xxx\Desktop\chromedriver_win32 (1)\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.maximize_window()

try:
driver.get(url)
except TimeoutError:
driver.execute_script("window.stop();")

time.sleep((randint(2, 3)))

r = requests.get(url, verify=False)
soup = BeautifulSoup(r.content, "html.parser")

g_data = soup.findAll("div", {"class": "audColResultatConcessionAdresse ng-binding"})

dict_name_r = []

for item in g_data:
dict_name_r.append(item.contents[1].findAll("h6", {"class": "audColResultatConcessionNom ng-binding"}))

print(dict_name_r)

非常感谢您的帮助

有两个主要原因,为什么会发生这种情况。首先,您可能使用了不存在的错误类、id或其他标识符。我想,事实并非如此。 更常见的原因是,您需要的数据是通过运行时获取和放置的。只要您从本地脚本请求它,就不会执行一些js内容(和其他内容)

一个可能的解决方案是,它能够模拟浏览器会话。看看吧


希望我能帮助你。祝你有愉快的一天。

我将尝试硒-ty:)