Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 15 additions & 5 deletions amzsear/core/AmzSear.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from amzsear.core.consts import URL_ADDONS, SEARCH_URL, DEFAULT_REGION
from amzsear.core.AmzProduct import AmzProduct
except ImportError:
from .amzsear.core import build_url
from .amzsear.core.consts import URL_ADDONS, SEARCH_URL, DEFAULT_REGION
from .amzsear.core.AmzProduct import AmzProduct
from . import build_url
from .consts import URL_ADDONS, SEARCH_URL, DEFAULT_REGION
from .AmzProduct import AmzProduct

"""
The AmzSear object is similar to a Python dict, with each item having a
Expand Down Expand Up @@ -74,14 +74,24 @@ def get_iter(it):
if url != None:
url = get_iter(url)
self._urls = url
html = [request.urlopen(request.Request(build_url(u), **URL_ADDONS)).read() for u in url]
html = []
for u in url:
req = request.Request(
build_url(u),
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0",
"Accept-Language": "en-US,en;q=0.9",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
}
)
html.append(request.urlopen(req).read())
if html != None:
html = get_iter(html)
html_element = [html_module.fromstring(h) for h in html]
if html_element != None:
html_element = get_iter(html_element)
for html_el in html_element:
products = html_el.cssselect('li[id*="result_"]')
products = html_el.cssselect('div[data-asin][data-component-type="s-search-result"]')
products = [x for x in products if x.cssselect('h2')]
products = [AmzProduct(elem) for elem in products]
if products != None:
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
lxml==3.8.0
lxml>=4.9.1
cssselect>=1.1.0
lxml_html_clean>=0.1.0
requests>=2.20.0
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
],
},
install_requires=[
'lxml==3.8',
"lxml>=4.9.1",
"cssselect>=1.1.0",
"lxml_html_clean>=0.1.0",
"requests>=2.20.0",
],
)