Pul*_*waj 4 html python beautifulsoup web-scraping bs4
当网页抓取页面的某些元素时,我遇到了一些奇怪的角色.似乎给出错误的字符是:
??? ??了¢¢阿?/?/>?/ ??? ?/¢¥?? %%?Á?????一个??>/???¥??>¥?¥©Á?>¢¥/ %% /¥??>?Â>Á?一个?Á????¢%Á?¥??? /%Á%Á?¥??> ?? />?Â??了???¥?? ??¢¥????¢`¢¢¢ ?? %%?Á??À?/?Á?¥?_Á?¥?> ??Á/¢?>ÀÁ??? Á>¥?? ??¥阿?/>??? __?> ?? /¥??>¢?Á
我的代码如下
url= "http://www.nsf.gov#######@#@#@##";
#webbrowser.open(url,new =new );
flagcnt+=1
if flagcnt%20==0: #autosleep for avoiding shut-out
print "flagcount: "
print flagcnt
time.sleep(5)
#Program Code extraction
r = requests.get (url)
sp=BeautifulSoup(r.content)
Run Code Online (Sandbox Code Playgroud)
页面:http://www.nsf.gov/awardsearch
我读了这个错误的所有页面,其中一些建议解码和编码,但他们似乎没有帮助.我不知道这里使用的是哪种编码.已经降级BS版本但没有帮助.任何帮助表示赞赏.Python 2.7 BS 4
niv*_*xer 11
这对我有用:
page_text = r.text.encode('utf-8').decode('ascii', 'ignore')
page_soupy = BeautifulSoup.BeautifulSoup(page_text)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8742 次 |
| 最近记录: |