Skip to content

Kent-Griffith/Crawler-Xpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

xpath

基于上一篇beautifulsoup模块,这一次学习用xpath模块写爬虫程序

不同之处在于:

使用User-Agent请求头随机更改和随机Referer自动更新避免相同User-Agent重复访问多次

使用自动翻页,使得程序更加灵活

以及更加使用的名字保存语法:grinning: :grinning: :grinning: :grinning:

image

img_url = list('http:'+item for item in img_src)

遍历列表img_src,在每个成员前面加上http:并重新赋值给img_url

for nurl,ntitle in zip(img_url,title): save_img(nurl,ntitle,url)

同时遍历两个列表

自动翻页函数,通过找到下一页的链接,从而让程序自己跳转下一页

image

当程序报错时,由被try和except包裹的主程序代码便跳出循环,结束程序:

image

About

入门爬虫程序

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages