spiders:你好污啊

'''python3
爬取网站:https://www.nihaowua.com/
爬取内容:撩妹金句
python库: requests + pyquery
'''

import requests
from pyquery import PyQuery as pq

url = 'https://www.nihaowua.com/'
headers = {
    'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/76.0.3809.87 Chrome/76.0.3809.87 Safari/537.36'
}

def spiders():
    re = requests.get(url=url, headers=headers)  # 爬取网页
    html = pq(re.text)
    text = html('section').text()  # 解析网页:section 节点 -> 取节点的文本内容
    return text

def main():
    count = 0
    while count < 100:
        text = spiders()
        print('第{}次爬取:{}'.format(count+1, text))
        count += 1

if __name__ == '__main__':
    main()
  • 执行结果
    在这里插入图片描述
发布了59 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_40313634/article/details/100568462