圆月山庄资源网 Design By www.vgjia.com
我们首先来看下实例代码:
from time import sleep import faker import requests from lxml import etree fake = faker.Faker() base_url = "http://angelimg.spbeen.com" def get_next_link(url): content = downloadHtml(url) html = etree.HTML(content) next_url = html.xpath("//a[@class='ch next']/@href") if next_url: return base_url + next_url[0] else: return False def downloadHtml(ur): user_agent = fake.user_agent() headers = {'User-Agent': user_agent,"Referer":"http://angelimg.spbeen.com/"} response = requests.get(url, headers=headers) return response.text def getImgUrl(content): html = etree.HTML(content) img_url = html.xpath('//*[@id="content"]/a/img/@src') title = html.xpath(".//div['@class=article']/h2/text()") return img_url[0],title[0] def saveImg(title,img_url): if img_url is not None and title is not None: with open("txt/"+str(title)+".jpg",'wb') as f: user_agent = fake.user_agent() headers = {'User-Agent': user_agent,"Referer":"http://angelimg.spbeen.com/"} content = requests.get(img_url, headers=headers) #request_view(content) f.write(content.content) f.close() def request_view(response): import webbrowser request_url = response.url base_url = '<head><base href="%s" rel="external nofollow" >' %(request_url) base_url = base_url.encode() content = response.content.replace(b"<head>",base_url) tem_html = open('tmp.html','wb') tem_html.write(content) tem_html.close() webbrowser.open_new_tab('tmp.html') def crawl_img(url): content = downloadHtml(url) res = getImgUrl(content) title = res[1] img_url = res[0] saveImg(title,img_url) if __name__ == "__main__": url = "http://angelimg.spbeen.com/ang/4968/1" while url: print(url) crawl_img(url) url = get_next_link(url)
python 爬虫如何执行自动下一页循环加载文字
from bs4 import BeautifulSoup import requests import time from lxml import etree import os # 该demo执行的为如何利用bs去爬一些文字 def start(): # 发起网络请求 html=requests.get('http://www.baidu.com') #编码 html.encoding=html.apparent_encoding #创建sp soup=BeautifulSoup(html.text,'html.parser') print(type(soup)) print('打印元素') print(soup.prettify()) #存储一下title 该方法没有提示直接展示 title=soup.head.title.string print(title) # 写入文本 with open(r'C:/Users/a/Desktop/a.txt','w') as f: f.write(title) print(time.localtime()) url_2 = 'http://news.gdzjdaily.com.cn/zjxw/politics/sz_4.shtml' def get_html_from_bs4(url): # response = requests.get(url,headers=data,proxies=ip).content.decode('utf-8') response = requests.get(url).content.decode('utf-8') soup = BeautifulSoup(response, 'html.parser') next_page = soup.select('#displaypagenum a:nth-of-type(9)')[0].get('href') # for i in nett print(next_page) next2='http://news.gdzjdaily.com.cn/zjxw/politics/'+next_page def get_html_from_etree(url): response = requests.get(url).content.decode('utf-8') html= etree.HTML(response) next_page = html.xpath('.//a[@class="PageNum"][8]/@href')[0] print(next_page) # next2='http://news.gdzjdaily.com.cn/zjxw/politics/'+next_page get_html_from_etree(url_2) if __name__ == '__main__': start()
标签:
python爬虫,下一页
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月02日
2024年11月02日
- 童丽2024 《千愁记旧情》8月最新 限量1:1母盘直刻[WAV+CUE][1.1G]
- 陈奕迅《认了吧》[新加坡纸盒版] [WAV+CUE][1.1G]
- 群星《小夫妻 电视原声带》[320K/MP3][113.44MB]
- 孙楠.2004-燃烧【华纳】【WAV+CUE】
- 群星.2003-英皇精挑细选VOL.1【英皇娱乐】【WAV+CUE】
- 林姗.2024-寄天的记忆【豪记】【FLAC分轨】
- 陈洁丽-《可改变HQ2》2024[WAV+CUE]
- 福田进一2024《魔鬼随想曲》WAV
- 群星《新歌龙卷风》2CD/DTS-ES[WAV]
- 群星《湮灭之潮 《明日之后》蓝潮资料片游戏原声带》[320K/MP3][50.49MB]
- 群星《湮灭之潮 《明日之后》蓝潮资料片游戏原声带》[FLAC/分轨][232.82MB]
- 威神V(WayV)《The Highest》[320K/MP3][45MB]
- lol全球总决赛lck二号种子是谁 S14全球总决赛lck二号种子队伍介绍
- 魔兽世界万圣节糖果任务怎么做 耶斯帕尔的万圣节糖果任务攻略
- s14全球总决赛晋级图在哪看 2024s14全球总决赛晋级图一览