Python 爬虫

安装 Python

安装包

php install requests
pip install beautifulsoup4
pip install lxml

代码

import requests
import sys
from bs4 import BeautifulSoup

url = 'http://xxx'
strhtml = requests.get(url)
strhtml.encoding = 'utf-8'
bs = BeautifulSoup(strhtml.text,'lxml')

# print(bs.title.string)

sys.stdout = open('log.txt', mode = 'w', encoding='utf-8')

for item in bs.find_all("a"):
    print(item.get_text())

http://www.jsphp.net/python/show-24-214-1.html
https://blog.csdn.net/macair123/article/details/79495877

140 total views, 4 views today

Revisions

Comments are closed.