【发布时间】:2020-07-19 03:17:04
【问题描述】:
我尝试通过 XPath 获取 HTML 元素,我尝试过这种方式,但它总是返回一个空字符串。 谁能告诉我,我如何通过 X-Path 获取元素?
for x in list_href_einrichtungen:
url = 'https://pflegefinder.bkk-dachverband.de/' + x
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text)
**doc = lxml.html.fromstring(source_code.content)
strasse = doc.xpath('div[3]/div[3]/table[1]/tbody/tr/td/div/div/div[1]/p[1]/text()[1]')**
name = soup.find('h2').text
uebergabeeinrichtung = Einrichtung("IK", name, 'Teststraße', '12345', 'Ort', "telefon",
'Telefax', 'email','internet')
list_einrichtungen.append(uebergabeeinrichtung)
print(name, strasse)
【问题讨论】:
-
这能回答你的问题吗? can we use xpath with BeautifulSoup?
标签: python html beautifulsoup lxml