我试图在新闻中抓取回复。在使用python进行Web抓取时出现错误
我试过很多次了。
但我只能看到Traceback。
请帮帮我。
我写这样的代码:
import re
import urllib.request
import urllib
import requests
from bs4 import BeautifulSoup
url='http://news.naver.com/main/ranking/read.nhn?mid=etc&sid1=111&rankingType=popular_week&oid=277&aid=0003773756&date=20160622&type=1&rankingSectionId=102&rankingSeq=1&m_view=1'
html=request.get(url)
#print(html.text)
a=html.text
bs=BeautifulSoup(a,'html.parser')
print(bs.prettify())
bs.find('span',class="u_cbox_contents")
当我运行此:bs.find( '跨越' 的class = “u_cbox_contents”)
我只能看到许多错误
错误是这样的。
SyntaxError: invalid syntax
如何修复代码以运行良好?
请帮帮我。
我运行这个python 3.4.4版本,windows 8.1 64x
感谢您的阅读。
永远,永远,永远,永远使用'urllib'时,你可以使用'requests'代替。 –
@AkshatMahajan你的意思是试过这段代码? : 进口重新 进口urllib.request里 从BS4进口BeautifulSoup URL =“HTTP://news.naver.com/main/ranking/read.nhn中旬=等与SID 1 = 111&rankingType = popular_week&OID = 277&援助= 0003773756&日期= 20160622&type = 1&rankingSectionId = 102&rankingSeq = 1&m_view = 1' html = urllib.request.urlopen(url) 但无效。我可以看到相同的错误 –
不,我的意思是你正在使用'urllib'库而不是'requests'库进行请求。 'request'只是更容易处理。做'html = requests.get(url)'。 –