解析在Python 3字符串搜索词,当我想用我感兴趣的术语只返回字符串,我可以这样做:Python中没有找到由BeautifulSoup
phrases = ["1. The cat was sleeping",
"2. The dog jumped over the cat",
"3. The cat was startled"]
for phrase in phrases:
if "dog" in phrase:
print(phrase)
这当然版画“2 。狗跳过猫“
现在我想要做的是使相同的概念与分析字符串在BeautifulSoup工作。例如,Craigslist拥有大量的A标签,但只有A标签中有“hdrlnk”的标签对我们很有帮助。所以我:
import requests
from bs4 import BeautifulSoup
url = "https://chicago.craigslist.org/search/apa"
r = requests.get(url)
soup = BeautifulSoup(r.content, "html.parser")
links = soup.find_all("a")
for link in links:
if "hdrlnk" in link:
print(link)
问题是不是打印所有A标签与“hdrlnk”里面,Python的打印什么。我不确定发生了什么问题。
我访问了链接,但无法找到包含“hdrlink”的文本的任何链接。 –