因此,我一直坐在这个问题有一点现在,我不断得到一个坏的请求错误时,运行下面的代码
url = input("Twitter link: ")
print("\n")
html_doc = urllib.request.urlopen(url)
soup = BeautifulSoup(html_doc, 'lxml')
name = soup.find('h1').a.text
location = soup.find('span', {'class' : 'ProfileHeaderCard-
locationText'}).text
locationstrip = location.strip()
created = soup.find('span', {'class' : 'ProfileHeaderCard-
joinDateText'}).text
birthday = soup.find('span', {'class' : 'ProfileHeaderCard-
birthdateText'}).text
birthdaystrip = birthday.strip()
posted = soup.find('a', {'class' : 'PhotoRail-headingWithCount'}).text
postedstrip = posted.strip()
print("Info")
print("-------- \n")
print(name)
print(locationstrip)
print(created)
print(birthdaystrip)
print(postedstrip)
url = "http://www.wikipedia.com/wiki/" + name
formedurl = urllib.request.Request(url, headers={'User-Agent': 'Chrome/70.0.3538.102'})
html_doc = urllib.request.urlopen(formedurl)
soup = BeautifulSoup(html_doc, 'lxml')
我读到你需要指定一个用户代理,所以我做了,使它看起来像一个合法的http请求,但我仍然得到这个错误。提前谢谢
您需要在
name
中用未得分的_
替换space
从浏览器中复制标题并逐个删除,直到找到最合适的标题集
相关问题 更多 >
编程相关推荐