Skip to content

Commit 9e17760

Browse files
committed
⬆️ Changed to my_fake_useragent
1 parent 17012bc commit 9e17760

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

scrape_amazon/util/urlFunctions.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import requests
2+
from my_fake_useragent import UserAgent
23

34
url_prefix = "https://www.amazon"
4-
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0", "Accept-Encoding":"gzip, deflate", "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "DNT":"1","Connection":"close", "Upgrade-Insecure-Requests":"1"}
5+
56
# random user-agent
7+
ua = UserAgent(family="chrome", os_family="windows")
8+
# ua = UserAgent(cache=False, use_cache_server=False, safe_attrs=("__injections__",))
69

7-
from fake_useragent import UserAgent
8-
ua = UserAgent(cache=False, use_cache_server=False)
910

1011
def construst_reviews_URL(domain: str, product_id: str) -> str:
1112
"""Constructs review URL.
@@ -16,19 +17,20 @@ def construst_reviews_URL(domain: str, product_id: str) -> str:
1617
"""
1718
return f"{url_prefix}.{domain}/dp/product-reviews/{product_id}"
1819

20+
1921
def get_URL(url: str) -> str:
2022
"""Gets the contents of a remote url.
2123
Args:
2224
url
2325
Returns:
2426
The content fetched from remote url.
2527
"""
26-
user_agent = ua.random
27-
while (True):
28-
content: str = requests.get(url, headers={'User-Agent': user_agent})
28+
user_agent = ua.random()
29+
while True:
30+
content: str = requests.get(url, headers={"User-Agent": user_agent})
2931
if "api-services-support@amazon.com" in content.text:
30-
user_agent = ua.random
32+
user_agent = ua.random()
3133
continue
3234
break
33-
34-
return content
35+
36+
return content

setup.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import setuptools
22

3-
with open('README.md') as readme_file:
3+
with open("README.md") as readme_file:
44
README = readme_file.read()
55

6-
setuptools.setup(name='scrape_amazon',
7-
version='0.1.4',
8-
description='Scrape Amazon Reviews',
9-
url='http://github.com/officialpm/scrape-amazon',
10-
author='Parth Maniar',
11-
author_email='officialparthmaniar@gmail.com',
12-
license='MIT',
13-
long_description_content_type="text/markdown",
14-
long_description=README,
15-
download_url="https://pypi.org/project/scrape-amazon",
16-
packages=setuptools.find_packages(),
17-
keywords=["Amazon", "Scrape", "Reviews", "Scraper", "Products"],
18-
python_requires='>=3.6',
19-
classifiers=[
20-
"Operating System :: OS Independent",
21-
"Intended Audience :: Developers",
22-
"Topic :: Utilities",
23-
"Natural Language :: English",
24-
"Programming Language :: Python :: 3",
25-
"Programming Language :: Python :: 3.6",
26-
"Programming Language :: Python :: 3.7",
27-
"Programming Language :: Python :: 3.8",
28-
"Programming Language :: Python :: 3 :: Only"
29-
], install_requires=['beautifulsoup4', 'pandas', 'p_tqdm', 'fake_useragent'],
30-
entry_points={
31-
'console_scripts': ['scrape-amazon=scrape_amazon.cli:get_reviews_cli'],
32-
}
33-
)
6+
setuptools.setup(
7+
name="scrape_amazon",
8+
version="0.1.4",
9+
description="Scrape Amazon Reviews",
10+
url="http://github.com/officialpm/scrape-amazon",
11+
author="Parth Maniar",
12+
author_email="officialparthmaniar@gmail.com",
13+
license="MIT",
14+
long_description_content_type="text/markdown",
15+
long_description=README,
16+
download_url="https://pypi.org/project/scrape-amazon",
17+
packages=setuptools.find_packages(),
18+
keywords=["Amazon", "Scrape", "Reviews", "Scraper", "Products"],
19+
python_requires=">=3.6",
20+
classifiers=[
21+
"Operating System :: OS Independent",
22+
"Intended Audience :: Developers",
23+
"Topic :: Utilities",
24+
"Natural Language :: English",
25+
"Programming Language :: Python :: 3",
26+
"Programming Language :: Python :: 3.6",
27+
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3 :: Only",
30+
],
31+
install_requires=["beautifulsoup4", "pandas", "p_tqdm", "my_fake_useragent"],
32+
entry_points={
33+
"console_scripts": ["scrape-amazon=scrape_amazon.cli:get_reviews_cli"],
34+
},
35+
)

0 commit comments

Comments
 (0)