用爬虫爬头条,返回如下结果



```python
import re
import requests
from bs4 import BeautifulSoup
from lxml import etree
url="https://www.toutiao.com/"
header={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"}
res=requests.get(url=url,headers=header)
patt='<div class="feed-card-article-l"><a href="(.*?)" target="_blank" rel="noopener class="title" aria-lable="(.*?)"><h2 title="(.*?)"</h2></a>'
res=re.findall(pattern=patt,string=res.text,flags=re.S)
print(res)


上面为源代码,下面是输出结果
[]
我尝试了几次,都没效果,希望有人能解答一下

打印res.text你看看返回的是什么!把Cookie加进去

正则表达式出错了,匹配的是空的,先看一下原网页中应该是有层级的,标签之间有空格,建议用.*?放在标签之间匹配空格🙈🙈🙈

今日头条文章.我以前写过.两种解决方法,.1.用selenium 2.设置应该是cookie值.而且这个cookie值可以写死.但是写死能活多久不清楚了.