爬取某个网址高清图片(Crawl a website HD picture)

本程序用到Python
用到的库requests,lxml
输入网址,
url = ”
获取源代码
ht = etree.HTML(a.text)
找到a标签中的href属性值
href_list = ht.xpath(‘//*[@id=”showImg”]/li/a/@href’)
利用循环语句获取多个a标签中的href属性值
for i in href_list:
在获取a标签中的链接源代码
html_img = etree.HTML(src.text)
找到的src属性值
img_ = html_img.xpath(‘/html/body/img[1]/@src’)[0]
打印src属性值,图片的链接
print(img_)

代码
import requests
from lxml import etree

url = ‘https://xxxx.xxx.com.cn/bizhi/5336_65991_2.html’

href_url = ‘https://xxxx.xxx.com.cn’

a = requests.get(url)

ht = etree.HTML(a.text)

href_list = ht.xpath(‘//*[@id=”showImg”]/li/a/@href’)

for i in href_list:
a_url = href_url+i
onclick = requests.get(a_url)
htm = etree.HTML(onclick.text)
img_url = htm.xpath(‘//*[@id=”tagfbl”]/a/@href’)[0]
img_src = href_url + img_url
src = requests.get(img_src)
html_img = etree.HTML(src.text)
img_ = html_img.xpath(‘/html/body/img[1]/@src’)[0]
print(‘”‘+img_+'”,’)

————————

This program uses python
Used library requests, lxml
Enter the web address,
url = ”
Get source code
ht = etree.HTML(a.text)
Locate the href attribute value in the a tag
href_ list = ht.xpath(‘//*[@id=”showImg”]/li/a/@href’)
Get the href attribute values in multiple a tags using circular statements
for i in href_ list:
Link source code in get a tag
html_ img = etree.HTML(src.text)
SRC attribute value found
img_ = html_ img.xpath(‘/html/body/img[1]/@src’)[0]
Print SRC attribute value, picture link
print(img_)

代码
import requests
from lxml import etree

url = ‘https://xxxx.xxx.com.cn/bizhi/5336_65991_2.html’

href_url = ‘https://xxxx.xxx.com.cn’

a = requests.get(url)

ht = etree.HTML(a.text)

href_list = ht.xpath(‘//*[@id=”showImg”]/li/a/@href’)

for i in href_list:
a_url = href_url+i
onclick = requests.get(a_url)
htm = etree.HTML(onclick.text)
img_url = htm.xpath(‘//*[@id=”tagfbl”]/a/@href’)[0]
img_src = href_url + img_url
src = requests.get(img_src)
html_img = etree.HTML(src.text)
img_ = html_img.xpath(‘/html/body/img[1]/@src’)[0]
print(‘”‘+img_+'”,’)