Soh*_*sif -1 python parsing beautifulsoup linkedin web-scraping
我是网络爬虫的新手,我想获取页面的html。但是当我运行程序时,我得到的html为空,控制台显示了javascript
from bs4 import BeautifulSoup
import requests
import urllib
url = "https://linkedin.com/company/1005"
r = requests.get(url)
html_content = r.text
soup = BeautifulSoup(html_content,'html.parser')
print (soup.prettify())
问题不BeautifulSoup只是服务器,服务器需要更多信息来使您访问此页面。现在,它发送JavaScript代码,将您重定向到登录页面。
您需要User-Agent标题才能获得此页面。
您可以使用http://httpbin.org/get看到User-Agent在您的浏览器。
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0'}
url = "https://linkedin.com/company/1005"
r = requests.get(url, headers=headers)
print(r.text)
soup = BeautifulSoup(r.text, 'html.parser')
print(soup.prettify())
| 归档时间: | 
 | 
| 查看次数: | 5619 次 | 
| 最近记录: |