我已经通读了以前的问题,关于在尝试刮取具有安全性的页面时出现403错误。大多数人建议使用“请求”来设置用户代理值。我已经在我想要刮取的页面上尝试了这个方法,虽然它消除了错误消息,但脚本现在只是挂起(我已经尝试等待大约10-15秒,等待第二个print语句生成任何结果)
有什么想法吗
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
print('Example: Search White Pages Smith in Frenchs Forest area:')
req = Request('https://www.whitepages.com.au/residential/results?name=Smith&location=Frenchs%20Forest', headers={'User-Agent': 'Mozilla/5.0'})
html = urlopen(req)
bs = BeautifulSoup(html.read(), 'html.parser')
print(bs.h1)
目前没有回答
相关问题 更多 >
编程相关推荐