【发布时间】:2018-11-12 14:41:56
【问题描述】:
这应该相当简单。我想计算通过网页搜索创建的链接。在此示例中,search 代表 Stack Overflow 上的“gwen stefani”。截至撰写本文时,结果数为 15。
import bs4 # beautiful soup 4
import requests
import webbrowser
url = "https://stackoverflow.com/search?q=gwen+stefani"
myURL = url
webbrowser.open(myURL)
page = requests.get(url).text
r = requests.get(myURL)
html_content = r.text
soup = bs4.BeautifulSoup(html_content, "html.parser")
print soup.title
for link in soup.find_all("a"):
print(link.get("href"))
当链接被打印出来时,它不包含任何提到的结果。我是汤的新手,现在我不确定我哪里出错了。
【问题讨论】:
-
你不需要 webbrowser,只需要 BeautifulSoup 和 requests。
-
我正在使用 webbrowser 仔细检查我的结果 :)
标签: python-2.7 web-scraping beautifulsoup