问题描述
我想从网站中给出的表中捕获数据,并将其存储到具有预定义列的Pandas数据框中。我尝试捕获相同的内容,但无法按列分离数据。 以下是我对此的尝试;
import pandas as pd
import lxml.html as lh
site= 'https://gadgets.ndtv.com/mobiles/guide/phone-under-10000-best-mobile-india-price-realme-redmi-samsung-vivo-camera-battery-2240177'
docc= lh.fromstring((requests.get(site)).content)
tr_= docc.xpath('//tr')
df = pd.DataFrame(columns=['Phones','rating (out of 10)','Price in India'])
for t in range(0,len(tr_)):
row= tr_[t]
for (value) in row.iterdescendants():
phone= (value.text)
#print(phone)
dataset = df.append({'Phones':str(phone)},ignore_index=True)
但是在这里,我无法捕获“电话” ,“评分(满分10分)” 和“印度价格”
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)