如图,本人今年才开始接触python,请各位大佬帮帮忙,我这个女生头发都要掉完了,因为这个问题食不下咽,哎,拜托各位大佬了!!!!
运行结果是一对中括号,可是我觉得自己的正则表达式没有写错啊。。。。好无语啊!!!要疯了
import requests
from requests.exceptions import RequestException
import re
def get_one_page(url):
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36',
}
try:
response=requests.get(url,headers=headers)
if response.status_code==200:
return response.text
return None
except RequestException:
return None
def parse_one_page(html):
pattern=re.compile('<dd>.*?board-index.*?>(\d+)<i>.*?data-src="(.*?)".*?name"><a'
+'.*?>(.*?)</a>.*?start">(.*?)</p>.*?releasetime">(.*?)</p>'
+'.*?integer">(.*?)</i>.*?fraction">(.*?)</i>.*?<dd>',re.S)
items=re.findall(pattern,html)
print(items)
def main():
url='http://maoyan.com/board/4?'
html=get_one_page(url)
parse_one_page(html)
if __name__ == "__main__":
main()