gpt4 book ai didi

python - HTTP 错误 999 : Request denied

转载 作者:太空狗 更新时间:2023-10-30 02:29:53 26 4
gpt4 key购买 nike

我正在尝试使用 BeautifulSoup 从 LinkedIn 抓取一些网页,但我不断收到错误“HTTP 错误 999:请求被拒绝”。有没有办法避免这个错误。如果您查看我的代码,我已经尝试过 Mechanize 和 URLLIB2,但两者都给我同样的错误。

from __future__ import unicode_literals
from bs4 import BeautifulSoup
import urllib2
import csv
import os
import re
import requests
import pandas as pd
import urlparse
import urllib
import urllib2
from BeautifulSoup import BeautifulSoup
from BeautifulSoup import BeautifulStoneSoup
import urllib
import urlparse
import pdb
import codecs
from BeautifulSoup import UnicodeDammit
import codecs
import webbrowser
from urlgrabber import urlopen
from urlgrabber.grabber import URLGrabber
import mechanize

fout5 = codecs.open('data.csv','r', encoding='utf-8', errors='replace')

for y in range(2,10,1):


url = "https://www.linkedin.com/job/analytics-%2b-data-jobs-united-kingdom/?sort=relevance&page_num=1"

params = {'page_num':y}

url_parts = list(urlparse.urlparse(url))
query = dict(urlparse.parse_qsl(url_parts[4]))
query.update(params)

url_parts[4] = urllib.urlencode(query)
y = urlparse.urlunparse(url_parts)
#print y



#url = urllib2.urlopen(y)
#f = urllib2.urlopen(y)

op = mechanize.Browser() # use mecahnize's browser
op.set_handle_robots(False) #tell the webpage you're not a robot
j = op.open(y)
#print op.title()


#g = URLGrabber()
#data = g.urlread(y)
#data = fo.read()
#print data

#html = response.read()
soup1 = BeautifulSoup(y)
print soup1

最佳答案

您应该使用 LinkedIn REST API ,直接或使用 python-linkedin .它允许直接访问数据,而不是试图抓取大量使用 JavaScript 的网站。

关于python - HTTP 错误 999 : Request denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30288642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com