【发布时间】:2017-01-30 03:37:30
【问题描述】:
我想在通过 python 中的BeautifulSoup 库获取链接的 HTML 后提取链接的标题。
基本上,整个标题标签是
<title>Imaan Z Hazir on Twitter: "Guantanamo and Abu Ghraib, financial and military support to dictators in Latin America during the cold war. REALLY, AMERICA? (3)"</title>
我想提取只有这个Guantanamo and Abu Ghraib, financial and military support to dictators in Latin America during the cold war. REALLY, AMERICA? (3)的"标签中的数据
我试过了
import urllib
import urllib.request
from bs4 import BeautifulSoup
link = "https://twitter.com/ImaanZHazir/status/778560899061780481"
try:
List=list()
r = urllib.request.Request(link, headers={'User-Agent': 'Chrome/51.0.2704.103'})
h = urllib.request.urlopen(r).read()
data = BeautifulSoup(h,"html.parser")
for i in data.find_all("title"):
List.append(i.text)
print(List[0])
except urllib.error.HTTPError as err:
pass
我也试过了
for i in data.find_all("title.""):
for i in data.find_all("title>""):
for i in data.find_all("""):
和
for i in data.find_all("quot"):
但是没有人在工作。
【问题讨论】:
-
我希望 BeautifulSoup 将
&quot;转换为",所以你只需要寻找"... -
@zvone 这是什么?
"?你的意思是"title<">"?
标签: python css-selectors beautifulsoup html-parser