Web_Scraping Techniques

Posted profesor

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Web_Scraping Techniques相关的知识,希望对你有一定的参考价值。

 

web_scraping_package.py

from bs4 import BeautifulSoup
import requests
session = requests.Session()
headers = {
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/80.0.3987.149 Safari/537.36,
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
}

 

import sys
sys.path

获取python的path

[‘‘, /usr/lib/python36.zip, /usr/lib/python3.6, /usr/lib/python3.6/lib-dynload, /home/christopher/.local/lib/python3.6/site-packages, /usr/local/lib/python3.6/dist-packages, /usr/lib/python3/dist-packages]

 

这里我们把

web_scraping_package.py

放到

/home/christopher/.local/lib/python3.6/site-packages

目录下

 

 

以后就可以直接import

from web_scraping_package import session, headers, BeautifulSoup

 

就不用再写一大串导入文件了。

 

以上是关于Web_Scraping Techniques的主要内容,如果未能解决你的问题,请参考以下文章

Kaggle比赛House Prices: Advanced Regression Techniques

COSC1076 Programming Techniques

Looping Techniques

COSC1284 Programming Techniques

Summary: DOM modification techniques

Practice telephone techniques