我正在尝试设置一个脚本,以便每天从网站中提取数据,但我很难让Python真正读取表—我不是一个专业的程序员。我试过两种方法:
1)用漂亮的汤刮桌子(页眉、行等),然后
2)使用网站的excel导出按钮
以下是准确的网站: https://scgenvoy.sempra.com/index.html#nav=/Public/ViewExternalLowOFO.getLowOFO%3Frand%3D200
到目前为止,我的代码是:
#Imports
import requests
import urllib.request
import pandas as pd
from lxml import html
import lxml.html as lh
from bs4 import BeautifulSoup
`URL ='https://scgenvoy.sempra.com/index.html#nav=/Public/ViewExternalLowOFO.getLowOFO%3Frand%3D200'`
#Create a handle, page, to handle the contents of the website
requests.packages.urllib3.disable_warnings()
page = requests.get(URL, verify=False)
我认为最简单的方法是用
xpath //*[@id="content"]/form/div[2]/div/table/tbody/tr/td[4]/table/tbody/tr/td[1]/a
非常感谢您的帮助!你知道吗
我会尝试识别“导出到excel”的API并使用该API。您可以从浏览器的开发人员工具中确定这一点。例如,以下是Google Chrome的Copy as Curl提供的:
API url为 https://scgenvoy.sempra.com/Public/ViewExternalLowOFO.submitLowOfoSaveAs
输入参数为:
请求方法为POST。你知道吗
现在可以使用python请求库或beautifulsoup库发出此请求,并为参数传递适当的值。你知道吗
给你一个主意,而不是自己解决。你知道吗
您的website正在用export按钮追加动态表数据。所以基本上您需要使用
Selenium
包来处理动态数据。根据浏览器下载selenium web驱动程序。你知道吗对于chrome浏览器:
http://chromedriver.chromium.org/downloads
为chrome浏览器安装web驱动程序:
硒教程
https://selenium-python.readthedocs.io/
导出Excel文件:
其中
"/usr/bin/chromedriver"
chrome web驱动程序路径。你知道吗下面是我的代码:
driver.get('https://scgenvoy.sempra.com/index.html#nav=/Public/ViewExternalLowOFO.getLowOFO%3Frand%3D200')
相关问题 更多 >
编程相关推荐