我正在尝试从以下网站下载CSV和JSON数据:https://worldpopulationreview.com/countries/countries-by-gdp/#worldCountries
import pandas as pd
import requests
from lxml import html,etree
url = "https://worldpopulationreview.com/countries/countries-by-gdp/#worldCountries"
# now I am not sure, how to click csv button of actual website
# also I am not sure how it will download the csv file
# to DOWNLOADS as like when I click the page
import pandas as pd
import requests
url = "https://worldpopulationreview.com/countries/countries-by-gdp/#worldCountries"
r = requests.get(url)
df = pd.read_html(r.text)[0]
df.to_csv('data.csv')
您可以使用selenium模拟单击csv下载按钮 https://selenium-python.readthedocs.io/getting-started.html#example-explained
你需要下载
pip install selenium
如果使用Chrome,请在此处下载Chrome驱动程序-Chrome driver。然后查找按钮/链接的xpath,我使用inspect元素查找xpath:要查找xpath,请执行以下操作:
相关问题 更多 >
编程相关推荐