代码是这样的,要如何改动啊
import requests
from pyquery import PyQuery as pq
from urllib.parse import urlencode
import re
def dizhi():
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3573.0 Safari/537.36'}
data = {
'q': '微信群',
'typeall': '1',
'suball': '1',
'timescope': 'custom:2018 - 12 - 20 - 0: 2018 - 12 - 22 - 0',
'Refer': 'g'
}
url = 'https://s.weibo.com/weibo/%25E5%25AE%259D%25E5%25A6%2588%25E7%25BE%25A4?' + urlencode(data)
wangzhi = requests.get(url,headers = headers)
return wangzhi.text
def jiexi(html):
doc = pq(html)
item = doc('.m3 li')
print(item('img').attr('src'))
def main():
html = dizhi()
jiexi(html)
if name == 'main':
main()
打印结果:
//ww4.sinaimg.cn/thumb150/475ee913ly1fydb7js7inj20orcmvx6q.jpg
1
15874103329 OP 打印 item 有很多图片,但是获取属性值只打印出了一个,如何将 item 中所有的图片打印出来啊
|
2
ClutchBear 2018-12-22 12:53:53 +08:00
item 所有的图片, 你要遍历才行 |
3
15874103329 OP @ClutchBear 哦哦,谢谢大佬
|
4
dreambig183 2018-12-22 20:59:31 +08:00 via Android
推荐用 scrapy 的 selector.或是直接用 scrapy 框架吧,真的很方便!!!
|