小编Pul*_*waj的帖子

Python Beautiful Soup'ascii'编解码器不能编码字符u'\ xa5'

当网页抓取页面的某些元素时,我遇到了一些奇怪的角色.似乎给出错误的字符是:

??? ??了¢¢阿?/?/>?/ ??? ?/¢¥?? %%?Á?????一个??>/???¥??>¥?¥©Á?>¢¥/ %% /¥??>?Â>Á?一个?Á????¢%Á?¥??? /%Á%Á?¥??> ?? />?Â??了???¥?? ??¢¥????¢`¢¢¢ ?? %%?Á??À?/?Á?¥?_Á?¥?> ??Á/¢?>ÀÁ??? Á>¥?? ??¥阿?/>??? __?> ?? /¥??>¢?Á

我的代码如下

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

html python beautifulsoup web-scraping bs4

4
推荐指数
1
解决办法
8742
查看次数

标签 统计

beautifulsoup ×1

bs4 ×1

html ×1

python ×1

web-scraping ×1