嗨,我正在尝试使用Python和美丽的汤刮网页。网页中有各种表格,其中有我想要的结果,但我很难: 1) 找到合适的桌子 2) 找到正确的两个单元格 3) 将单元格1和单元格2分别写入字典键和值中。你知道吗
到目前为止,在发出请求并解析HTML之后,我使用:
URL='someurl.com'
def datascrape(url):
page=requests.get(url)
print ("requesting page")
soup = BeautifulSoup(page.content, "html.parser")
return(soup)
soup=datascrape(URL)
results = {}
for row in soup.findAll('tr'):
aux = row.findAll('td')
try:
if "Status" in (aux.stripped_strings):
key=(aux[0].strings)
value=(aux[1].string)
results[key] = value
except:
pass
print (results)
不幸的是,“结果”总是空的。我真的不知道我哪里出错了。有谁能开导我一下吗?你知道吗
我不知道你为什么要用findAll()而不是find_all(),因为我对网页抓取还比较陌生,但是我认为这会给你带来你想要的结果。你知道吗
希望这有帮助!你知道吗
如果只是在状态和不适用之后,可以使用位置n类型的css选择器。这取决于页面的位置是否相同。你知道吗
相关问题 更多 >
编程相关推荐