我想使用Python提取网页的标题。我按照说明操作,获得了大多数网站的标题。
import requests
from bs4 import BeautifulSoup
# target url
url = 'https://www.geeksforgeeks.org/'
# making requests instance
reqs = requests.get(url)
# using the BeaitifulSoup module
soup = BeautifulSoup(reqs.text, 'html.parser')
# displaying the title
print("Title of the website is : ")
for title in soup.find_all('title'):
print(title.get_text())
但我无法获得网站1688.com的标题。例如:https://detail.1688.com/offer/629606486448.html
你能帮我取下这一页的标题吗?谢谢
我相信这是因为1688.com包含了一个robots.txt,它最有可能防止僵尸/网络抓取。你还可以看到geeksfogees.com允许网络抓取。我建议不要尝试抓取,或者设置一个简单的正则表达式(我知道,很糟糕(来搜索标题。