如何简单爬取电影天堂里的电影链接并且写入自己本机的txt文件中?(看下面的代码,拿走不谢)
import re
import requests
from lxml import etree
url=" https://www.dytt8.net/"
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',}
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
k=requests.get(url,headers=headers)
print(k)
k.encoding='gb2312'
print(k.text)
# print(c)
#b=re.findall(r'[\u4e00-\u9fff]{2}.[\u4e00-\u9fff]{3}',k.text)
b=re.findall(r'href=".{0,}".*',k.text)
data=open(r"C:\Users\PC-win10-22\Desktop\jj.txt","w")
for i in b:
print(i)
data.write(i)
data.close()