Python代码没有输出任何东西

2024-10-01 13:35:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了以下代码来对一些数据进行爬网,如下所示:

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。你知道吗

有人能告诉我问题是什么,怎么解决吗?你知道吗


Tags: reurlgetreturnrequestdefhtmlpage