我检查了类似的问题,但找不到解决方案......
我正在尝试从以下页面中获取额外旅行时间的分钟数 (46):https://www.tomtom.com/en_gb/trafficindex/city/istanbul
我尝试了两种方法(Xpath 和 find 类),但都给出了空返回。
import requests
from bs4 import BeautifulSoup
from lxml.html import fromstring
page = requests.get("https://www.tomtom.com/en_gb/trafficindex/city/istanbul")
tree = fromstring(page.content)
soup = BeautifulSoup(page.content, 'html.parser')
#print([type(item) for item in list(soup.children)])
html = list(soup.children)[2]
g_data = soup.find_all("div", {"class_": "big.ng-binding"})
congestion = tree.xpath("/html/body/div/div[2]/div[2]/div[2]/section[2]/div/div[2]/div/div[2]/div/div[2]/div[1]/div[1]/text()")
print(congestion)
print(len(g_data))
Run Code Online (Sandbox Code Playgroud)
我错过了一些明显的东西吗?
非常感谢您的帮助!