我编写了以下代码来对一些数据进行爬网,如下所示:
import urllib.request, re
def get_content(page):
url = 'https://www.liepin.com/zhaopin/?sfrom=click-pc_homepage-centre_searchbox-search_new&key=python&curPage=1'.format(page)
a = urllib.request.urlopen(url)
html = a.read()
html = html.decode('utf-8')
#print (html)
return html
def get(html):
reg = re.compile(r'class="job-info" >[^.]+<span class="job-name" title="(.*?)" >.*?',re.S)
items = re.findall(reg, html)
return items
for j in range(1,10):
html = get_content(j)
for i in get(html):
print (i)
with open("liepin.txt",'a')as f:
f.write(i)`
但是,它不会打印任何内容。然后我怀疑这可能是re引起的,所以我检查了regex,但是-regex朋友告诉我re是对的,它可以匹配html。你知道吗
有人能告诉我问题是什么,怎么解决吗?你知道吗
使用此解析器解决此问题https://www.crummy.com/software/BeautifulSoup/bs4/doc/
相关问题 更多 >
编程相关推荐