|  | 
 
| 
import requests
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  import re
 from bs4 import BeautifulSoup
 
 html = requests.get(url='http://58921.com/alltime/2020')
 html.encoding = 'utf-8'
 html = html.text
 #print(html)
 
 rule = re.compile(r'<td><a title=".*?" href="/film/.*?">.*?</a></td>')
 title = re.findall(rule,html)
 print(title)
 前面的html没问题,就是title打印出来一直是个空列表,求大佬解惑
 
试试这个 复制代码import re
from bs4 import BeautifulSoup
import urllib.request as ur
req = ur.Request('http://58921.com/alltime/2020')
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4843.400 QQBrowser/9.7.13021.400')
page = ur.urlopen(req)
html = page.read().decode('utf-8')
print(html)
rule = re.compile(r'<a href="/film/\d+" title="(.*?)">')
title = re.findall(rule,html)
print(title)
 | 
 |