spiders:你好污啊

  • 2019 年 10 月 10 日
  • 笔记

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/weixin_40313634/article/details/100568462

'''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()
  • 执行结果