[![在此处输入图像描述][1]][1][![在此处输入图像描述][1]][1]按下面的代码将HTML web表打印为python脚本输出。 然后我尝试将其转换为DF,然后导出到CSV,但失败了
import time
from bs4 import BeautifulSoup
from selenium import webdriver
import pandas as pd
url = 'http://www.altrankarlstad.com/wisp'
driver = webdriver.Chrome('C:\\Users\\rugupta\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Python 3.7\\chromedriver.exe')
driver.get(url)
time.sleep(100)
text_field = driver.find_elements_by_xpath('//*[@id="root"]/div/div/div/div[2]/table')
#print (text_field[0].text)
data= text_field[0].text
#Works fine until above section
df= pd.DataFrame(data)
df.to_csv("output.csv")
(but no success here)!
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/NpGk2.jpg
问题是selenium会检测到页面已经被加载,但是,您需要等待包含您试图获取的数据的表被加载。因此,您需要告诉selenium等待,直到找到表中的元素。对于这种特殊情况,表中的每个“job”都由一个名为“css-58”的特定类名定义。解决方案如下:
在这一点上,您唯一需要做的就是弄清楚您希望如何定义数据帧的结构。你知道吗
相关问题 更多 >
编程相关推荐