Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reference user agent for ebay crawler #8

Merged
merged 1 commit into from
May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flathunter/crawl_ebaykleinanzeigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class CrawlEbayKleinanzeigen:
__log__ = logging.getLogger(__name__)
USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
URL_PATTERN = re.compile(r'https://www\.ebay-kleinanzeigen\.de')

def __init__(self):
Expand All @@ -23,7 +24,7 @@ def get_results(self, search_url):
return entries

def get_page(self, search_url):
resp = requests.get(search_url) # TODO add page_no in url
resp = requests.get(search_url, headers={'User-Agent': self.USER_AGENT}) # TODO add page_no in url
if resp.status_code != 200:
self.__log__.error("Got response (%i): %s" % (resp.status_code, resp.content))
return BeautifulSoup(resp.content, 'html5lib')
Expand Down Expand Up @@ -80,7 +81,7 @@ def extract_data(self, soup):
@staticmethod
def load_address(url):
# extract address from expose itself
expose_html = requests.get(url).content
expose_html = requests.get(url, headers={'User-Agent': CrawlEbayKleinanzeigen.USER_AGENT}).content
expose_soup = BeautifulSoup(expose_html, 'html.parser')
try:
street_raw = expose_soup.find(id="street-address").text
Expand Down