python3错误 之NameError: name 'cookielib' is not defined
问题:
Python 3 改成 http.cookiejar了
改进办法
print('第三种方法,cookie处理')
import http.cookiejar
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
问题:
Python 3 改成 http.cookiejar了
改进办法
print('第三种方法,cookie处理')
import http.cookiejar
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
2018-09-26
最新回答 / longmoxxx
应该是连接取的不对吧。百科的网页有更新。试试这个
links = soup.find_all('a',href=re.compile(r"/item/"))
2018-09-25
我用pycharm 编写的:
import re
from bs4 import BeautifulSoup
html_doc = """
...
"""
soup = BeautifulSoup(html_doc,'html.parser',from_encoding='utf-8')
print '获取所有的链接'
links = soup.find_all('a')
for link in links:
print link.name,link['href'],link.get_text()
.....
遇到的坑,新建的文件名不能包含bs4不然系统报错
import re
from bs4 import BeautifulSoup
html_doc = """
...
"""
soup = BeautifulSoup(html_doc,'html.parser',from_encoding='utf-8')
print '获取所有的链接'
links = soup.find_all('a')
for link in links:
print link.name,link['href'],link.get_text()
.....
遇到的坑,新建的文件名不能包含bs4不然系统报错
2018-09-20