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()
  • 執行結果

Tags: