解析在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」的文本的任何鏈接。 –