可以爬取wiki百科中文网
url修改成:https://api.bilibili.com/x/web-interface/search/type?search_type=video&highlight=1&keyword=%E5%BE%90%E5%A4%A7SAO&page=3&jsonp=jsonp&callback=__jp1直接设置page就可以了
三个猪,真是笑死了,统一回复吧,
第一位的错误 if not re. search("\.(jpg|JPG)$", "url"): 改成这样 : if not re. search("\.(jpg|JPG)$", url["href"]):
主要改这里 "url"----->>>> url["href"]
第二位和第三位的错误一模一样,你两相互抄的吗? if not re. search(\.(jpg|JPG$) ' aurl[' href'):改成这样 : if not re. search("\.(jpg|JPG)$", url["href"]):
主要改这里 (\.(jpg|JPG$)---------->>>>("\.(jpg|JPG)$
列表里边是元组吧
re.complie("^http://example.webscraping.com/places/default/view")
解决了,原来是用错括号了,把[ ]看成()了
#!/usr/bin/env python # -*- coding:utf-8 -*- import io import sys from urllib import request from bs4 import BeautifulSoup import re sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') resp = request.urlopen("http://news.baidu.com/").read().decode("utf-8") soup =BeautifulSoup(resp,"html.parser") listUrls=soup.find_all("a",href=re.compile(".*\/\/news\.baidu.*")) for url in listUrls: print (url.get_text(),"<------------>"+url["href"])
这个是我的,你可以参考一下
u'\u5b8f'
用这样显示
soup.find('table').get_text()
解决Python certificate verify failed的问题
http://www.111cn.net/phper/python/103529.htm
这是我百度到的,也没有验证,虽然我没碰到这个问题,但还是先放在这里吧(万一哪天踩到了)
如果题主解决了这个问题,顺便也回来告诉我一下正解吧~
输入python 回车,然后输入import urllib试试
你用的是PyCharm吧,这个说明运行正常,你把代码贴出来看看是什么个情况
最后一行 print(url["herf"])
里面的 herf 改成 href 试试看